home *** CD-ROM | disk | FTP | other *** search
/ Best of www.BestZips.com (Collector's Edition) / Best of WWW.BESTZIPS.COM Collector's Edition (JCSM Shareware) (JCS Marketing).ISO / tutorial / adatu311.zip / BOOK.ADA < prev    next >
Text File  |  1996-01-10  |  13KB  |  314 lines

  1. -- BOOK.ADA   Ver. 3.11   10-JAN-1996   Copyright 1988-1996 John J. Herro
  2. --
  3. -- SOFTWARE INNOVATIONS TECHNOLOGY          http://members.aol.com/AdaTutor
  4. -- 1083 MANDARIN DR NE                      ftp://members.aol.com/AdaTutor
  5. -- PALM BAY FL 32905-4706
  6. --                                          johnherro@aol.com
  7. -- (407) 951-0233                           john.herro%374-38-2@satlink.oau.org
  8. --
  9. -- This program creates two printable "book" files from the tutorial text in
  10. -- ADA_TUTR.DAT.  This is by no means required for the course, but is provided
  11. -- because several users have asked for it.  Be prepared to print about 500
  12. -- pages!  For the format of the input data file, please see the preliminary
  13. -- comments in ADA_TUTR.ADA.
  14. --
  15.  
  16. with Direct_IO, Text_IO; use Text_IO;
  17. procedure Book is
  18.    subtype Block_Subtype is String(1 .. 64);
  19.    package Random_IO is new Direct_IO(Block_Subtype);
  20.    IxSize     : constant := 35;               -- Number of blocks in the index.
  21.    Data_File  : Random_IO.File_Type;   -- The file from which screens are read.
  22.    P          : File_Type;                   -- The output file, to be printed.
  23.    Block      : Block_Subtype;               -- Block read from the input file.
  24.    Vpos       : Integer;                        -- Number of the current block.
  25.    Hpos       : Integer;              -- Current position within current block.
  26.    Highest_SN : Integer;                -- Highest screen number in the course.
  27.    Middle_SN  : Integer;          -- Screen number when we change output files.
  28.    Indx       : String(1 .. 64*IxSize);            -- Index from the Data File.
  29.    Answer     : String(1 .. 80);                 -- User response to questions.
  30.    Len        : Integer;                                   -- Length of Answer.
  31.    File_OK    : Boolean := False;    -- True when data file opens successfully.
  32.    Legal_Note : constant String := " Copyright 1988-96 John J. Herro ";
  33.                        -- Legal_Note isn't used by the program, but it causes
  34.                        -- most compilers to place this string in the .EXE file.
  35.    procedure Open_Input_File is separate;
  36.    procedure Open_Output_File(S: in String) is separate;
  37.    procedure Print_Instructions is separate;
  38.    procedure Print_Title_Page is separate;
  39.    procedure Print_Screen(SN : in Integer) is separate;
  40. begin
  41.    Open_Input_File;
  42.    if File_OK then
  43.       Print_Instructions;
  44.       Open_Output_File("FIRST");
  45.       Print_Title_Page;
  46.       Middle_SN := (101 + Highest_SN)/2;
  47.       for SN in 101 .. Highest_SN loop
  48.          if SN = Middle_SN then
  49.             Close(P);
  50.             Open_Output_File("SECOND");
  51.          end if;
  52.          Print_Screen(SN);
  53.       end loop;
  54.       Put_Line("Both book files are created and ready for printing.");
  55.       Random_IO.Close(Data_File);
  56.       Close(P);
  57.    end if;
  58. end Book;
  59.  
  60. separate (Book)
  61. procedure Open_Input_File is
  62.    Data_File_Name : constant String := "ADA_TUTR.DAT";
  63. begin
  64.    Random_IO.Open(Data_File, Random_IO.In_File, Data_File_Name);
  65.    for I in 1 .. IxSize loop             -- Read index from start of Data File.
  66.       Random_IO.Read(Data_File, Item => Block, From => Random_IO.Count(I));
  67.       Indx(64*I - 63 .. 64*I) := Block;
  68.    end loop;
  69.    Highest_SN := Integer'Value(Indx(6 .. 8));
  70.    File_OK := True;
  71. exception
  72.    when Random_IO.Name_Error =>
  73.       Put("I'm sorry.  The file " & Data_File_Name & " seems to be missing.");
  74.    when others =>
  75.       Put("I'm sorry.  The file " & Data_File_Name);
  76.       Put_Line(" seems to have the wrong form.");
  77. end Open_Input_File;
  78.  
  79.  
  80.  
  81. separate (Book)
  82. procedure Open_Output_File(S: in String) is
  83.    OK : Boolean := False;                 -- True when file opens successfully.
  84. begin
  85.    Put_Line("Please type the name of the output file for the " & S & " half");
  86.    Put("of the tutorial:  ");
  87.    Get_Line(Answer, Len);
  88.    while not OK loop
  89.       begin
  90.          Create(File => P, Mode => Out_File, Name => Answer(1 .. Len));
  91.          OK := True;
  92.       exception
  93.          when others => null;
  94.       end;
  95.       if not OK then
  96.          Put_Line("Unable to create file.  Please retype name:  ");
  97.          Get_Line(Answer, Len);
  98.       end if;
  99.    end loop;
  100.    New_Line(2);
  101. end Open_Output_File;
  102.  
  103. separate (Book)
  104. procedure Print_Instructions is
  105. begin
  106.    Put_Line("This program creates two printable ""book"" files from the");
  107.    Put_Line("tutorial text in ADA_TUTR.DAT.  This is by no means required");
  108.    Put_Line("for the course, but is provided because several users have");
  109.    Put_Line("asked for it.  Be prepared to print about 500 pages!");
  110.    New_Line(2);
  111. end Print_Instructions;
  112.  
  113.  
  114.  
  115. separate (Book)
  116. procedure Print_Title_Page is
  117.    S : constant String(1 .. 11) := (others => ' ');
  118. begin
  119.    New_Page(P);
  120.    New_Line(P);
  121.    Put_Line(P,S & "   AAA   DDDD    AAA          TTTTT  U   U  TTTTT  RRRR");
  122.    Put_Line(P,S & "  A   A  D   D  A   A           T    U   U    T    R   R");
  123.    Put_Line(P,S & "  AAAAA  D   D  AAAAA   ===     T    U   U    T    RRRR");
  124.    Put_Line(P,S & "  A   A  D   D  A   A           T    U   U    T    R  R");
  125.    Put_Line(P,S & "  A   A  DDDD   A   A           T     UUU     T    R   R");
  126.    New_Line(P);
  127.    Put_Line(P,S & "This is a copy of the tutorial text from ADA-TUTR, The");
  128.    Put_Line(P,S & "Interactive Ada Tutor, ver. 3.11.  BEGIN WITH SCREEN 104.");
  129.    New_Line(P);
  130.    Put_Line(P,S & "            Copyright 1988-1996 John J. Herro");
  131.    New_Line(P);
  132.    Put_Line(P,S & "You may copy this book, in printed or machine-readable");
  133.    Put_Line(P,S & "form, if you observe the Shareware notice in Screen 104.");
  134.    Put_Line(P,S & "Please distribute complete copies of the ADA-TUTR program");
  135.    Put_Line(P,S & "along with this book.  If you don't have a copy of");
  136.    Put_Line(P,S & "ADA-TUTR, send $35 for a registered copy on a 3.5-inch");
  137.    Put_Line(P,S & "diskette for full use by one individual, or visit us on.");
  138.    Put_Line(P,S & "the World Wide Web, download a trial copy, and register");
  139.    Put_Line(P,S & "later for $25.");
  140.    New_Line(P);
  141.    Put_Line(P,S & "             SOFTWARE INNOVATIONS TECHNOLOGY");
  142.    Put_Line(P,S & "                   1083 MANDARIN DR NE");
  143.    Put_Line(P,S & "                  PALM BAY FL 32905-4706");
  144.    New_Line(P);
  145.    Put_Line(P,S & "                      (407) 951-0233");
  146.    New_Line(P);
  147.    Put_Line(P,S & "             http://members.aol.com/AdaTutor");
  148.    Put_Line(P,S & "              ftp://members.aol.com/AdaTutor");
  149.    New_Page(P);
  150.    New_Line(P);
  151. end Print_Title_Page;
  152.  
  153. separate (Book)
  154. procedure Print_Screen(SN : in Integer) is
  155.    Expanding  : Boolean := False;       -- True when expanding multiple spaces.
  156.    Literal    : Boolean := False;        -- True to print next character as is.
  157.    Prompting  : Boolean := False;      -- True for first character in a prompt.
  158.    Bold       : Boolean := False;        -- True when text is being emphasized.
  159.    Out1, Out2 : String(1 ..120) := (others => ' ');    -- Lines of output text.
  160.    Place      : Integer := 1;         -- Current position within Out1 and Out2.
  161.    Limit      : Integer;           -- Position of last non-space char. in Out2.
  162.    Line_Num   : Integer := 1;                  -- Current line being displayed.
  163.    Space      : constant String(1 .. 69) := (others => ' ');
  164.    procedure Show(C : in Character) is separate;
  165.    procedure Screen_Char is separate;
  166.    procedure End_Of_Screen is separate;
  167. begin
  168.    if SN = 103 then
  169.       Put(P, Space(1 .. 27) & "*** X TAKES YOU HERE. ***");
  170.       Put_Line(P, Space(1 .. 17) & "Screen 103");
  171.    else
  172.       Put_Line(P, Space & "Screen" & Integer'Image(SN));
  173.    end if;
  174.    New_Line(P, 2);
  175.    Vpos := 95*(Character'Pos(Indx(SN*4 - 394)) - 32) +        -- Point to start
  176.                Character'Pos(Indx(SN*4 - 393)) - 32;          -- of current
  177.    Hpos := Character'Pos(Indx(SN*4 - 392)) - 32;              -- screen.
  178.    Random_IO.Read(Data_File, Item => Block, From => Random_IO.Count(Vpos));
  179.    while Block(Hpos) /= '[' or Expanding or Literal loop -- [ starts ctrl info.
  180.       Screen_Char;
  181.    end loop;
  182.    End_Of_Screen;
  183. end Print_Screen;
  184.  
  185. separate (Book.Print_Screen)
  186. procedure Show(C : in Character) is
  187. begin
  188.    Out1(Place) := C;
  189.    if Bold then
  190.       Out2(Place) := '-';
  191.    end if;
  192.    Place := Place + 1;
  193. end Show;
  194.  
  195.  
  196.  
  197. separate (Book.Print_Screen)
  198. procedure Screen_Char is
  199.    procedure Process_Char is separate;
  200. begin
  201.    if Expanding then
  202.       if Block(Hpos) = '!' then
  203.          Literal := True;
  204.       else
  205.          for I in Integer range 1 .. Character'Pos(Block(Hpos)) - 32 loop
  206.             Show(' ');
  207.          end loop;
  208.       end if;
  209.       Expanding := False;
  210.    elsif Literal then
  211.       Show(Block(Hpos));
  212.       Literal := False;
  213.    elsif Prompting then
  214.       Prompting := False;
  215.       if Block(Hpos) = 'b' then
  216.          Put(P, "Please type a space to go on, or B to go back.");
  217.       elsif Block(Hpos) = 'q' then
  218.          PUT(P, "Please type a space to go on, or B or Q to go ");
  219.          PUT(P, "back to the question.");
  220.       else
  221.          Process_Char;
  222.       end if;
  223.    else
  224.       Process_Char;
  225.    end if;
  226.    Hpos := Hpos + 1;
  227.    if Hpos > Block'Length then
  228.       Vpos := Vpos + 1;
  229.       Hpos := 1;
  230.       Random_IO.Read(Data_File, Block, From => Random_IO.Count(Vpos));
  231.    end if;
  232. end Screen_Char;
  233.  
  234. separate (Book.Print_Screen.Screen_Char)
  235. procedure Process_Char is
  236. begin
  237.    case Block(Hpos) is
  238.       when '{'    => Put_Line(P, Out1(1 .. Place - 1));
  239.                      Limit := Out2'Last;
  240.                      while Limit > 0 and then Out2(Limit) = ' ' loop
  241.                         Limit := Limit - 1;
  242.                      end loop;
  243.                      Put_Line(P, Out2(1 .. Limit));
  244.                      Out2 := (others => ' ');
  245.                      Line_Num := Line_Num + 1;
  246.                      Out1 := (others => ' ');
  247.                      Place := 1;
  248.       when '@'    => Expanding := True;                  -- @ = several spaces.
  249.       when '^'    => Show(' ');                          -- ^ = bright + space.
  250.                      Bold := True;
  251.       when '~'    => Bold := False;                      -- ~ = normal + space.
  252.                      Show(' ');
  253.       when '%'    => Bold := True;                       -- % = bright.
  254.       when '`'    => Bold := False;                      -- ` = normal.
  255.       when '}'    => for I in Line_Num .. 23 loop        -- } = go to line 24.
  256.                         New_Line(P, 2);
  257.                      end loop;
  258.                      Prompting := True;
  259.       when '\'    => Show(' ');                          -- \ = rev. vid. + sp.
  260.       when '$'    => if SN = 103 then                    -- $ = screen #.
  261.                         Show(' '); Show('_'); Show('_'); Show('_');
  262.                      else
  263.                         Show('$');
  264.                      end if;
  265.       when '#'    => if SN = 103 then                    -- # = % completed.
  266.                         Show(' '); Show('_'); Show('_');
  267.                      else
  268.                         Show('#');
  269.                      end if;
  270.       when others => Show(Block(Hpos));
  271.    end case;
  272. end Process_Char;
  273.  
  274. separate (Book.Print_Screen)
  275. procedure End_Of_Screen is
  276.    Ctrl_Info : Block_Subtype;          -- Control info. for the current screen.
  277.    I         : Integer;                     -- Used to index through Ctrl_Info.
  278. begin
  279.    Put_Line(P, Out1(1 .. Place - 1));
  280.    Limit := Out2'Last;
  281.    while Limit > 0 and then Out2(Limit) = ' ' loop
  282.       Limit := Limit - 1;
  283.    end loop;
  284.    Put_Line(P, Out2(1 .. Limit));
  285.    Place := 1;
  286.    while Block(Hpos) /= ']' loop    -- Read control information from Data File.
  287.       Hpos := Hpos + 1;
  288.       if Hpos > Block'Length then
  289.          Vpos := Vpos + 1;
  290.          Hpos := 1;
  291.          Random_IO.Read(Data_File, Block, From => Random_IO.Count(Vpos));
  292.       end if;
  293.       Ctrl_Info(Place) := Block(Hpos);
  294.       Place := Place + 1;
  295.    end loop;
  296.    if Ctrl_Info(1 .. Place - 1) = "]" then
  297.       Put_Line(P, "(Program ends after this screen.)");
  298.    elsif Ctrl_Info(1 .. Place - 1) = "#]" then
  299.       Put_Line(P, "(User types the next screen number.)");
  300.    else
  301.       I := 1;
  302.       while I + 4 < Place loop
  303.          Put(P, "  '" & Ctrl_Info(I) & "' " & Ctrl_Info(I+1..I+3));
  304.          I := I + 4;
  305.          if I = 33 then
  306.             New_Line(P);
  307.          end if;
  308.       end loop;
  309.       New_Line(P);
  310.    end if;
  311.    New_Page(P);
  312.    New_Line(P);
  313. end End_Of_Screen;
  314.